'''
Company: TWL
Author: xue jian
Email: xuejian@kanzhun.com
Date: 2020-10-27 17:19:03
'''
#
# @lc app=leetcode.cn id=91 lang=python3
#
# [91] 解码方法
#

# @lc code=start
class Solution:
    def numDecodings(self, s: str) -> int:
        if s=='0':
            return 0
        if s[0]!='0':
            before = 1
            ans = 1
        else:
            before = 0
            ans = 0
        for i, v in enumerate(s):
            tmp = ans
            if v=='0' and i>0 and (s[i-1]=='0' or s[i-1]>'2'): #这个情况比较特殊，需要特殊处理。
                return 0
            if i>0 and int(s[i-1:i+1])<=26 and v!='0' and s[i-1]!='0':
                ans+=before
            elif v=='0': #这个情况太特殊，需要特殊处理
                ans=before
            before = tmp
        return ans
# @lc code=end

if __name__ == "__main__":
    solution = Solution()
    s='230'
    print(solution.numDecodings(s))